package com.example.onlinemusicserver2024.controller;

import com.example.onlinemusicserver2024.common.R;
import com.example.onlinemusicserver2024.model.domain.Singer;
import com.example.onlinemusicserver2024.service.SingerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class SingerController {

    @Autowired
    SingerService singerService;

    @GetMapping("/singer")
    public R allSinger(@RequestParam(required = false) Integer sex) {
        System.out.println("查询歌手列表,sex=" + sex);
        R result = singerService.allSinger(sex);
        return result;
    }


    /**
     * 用于添加歌手
     *
     * @param singer
     * @return
     */
    @PostMapping("/singer/add")
    public R addSinger(@RequestBody Singer singer) {
        System.out.println("添加歌手：" + singer.toString());
        R result = singerService.addSinger(singer);
        return result;
    }

    /**
     * 更新歌手信息
     *
     * @param singer
     * @return
     */
    @PostMapping("/singer/update")
    public R updateSinger(@RequestBody Singer singer) {
        System.out.println("更新歌手：" + singer.toString());
        R result = singerService.updateSinger(singer);
        return result;
    }

    /**
     * 删除歌手
     *
     * @param id
     * @return
     */
    @DeleteMapping("/singer/delete")
    public R deleteSinger(@RequestParam int id) {
        System.out.println("删除歌手，id=" + id);
        R result = singerService.deleteSinger(id);
        return result;

    }

}
